<template>

	<!-- top的高度等于悬浮菜单tabs的高度 -->
	<mescroll-uni @init="mescrollInit" :height="height" :down="downOption" @down="downCallback" :up="upOption"
		@up="upCallback">
		<!-- <view class="Goos-List"> -->
			<view class="deliver-query" v-if="keyword=='1'">
				<view class="deliver-time" ontap="showPopup">

					<image src="/static/img/index/query_time.png" style="width:28rpx;height:28rpx;"></image>
					<picker mode="date" :value="startDeta" :start="startTime" :end="endTime" @change="startDateChange">
						<view class="picker">
							{{startDeta}}
						</view>
					</picker>

				</view>
				<view class="line">至</view>
				<view class="deliver-time" ontap="showPopup">

					<image src="/static/img/index/query_time.png" style="width:28rpx;height:28rpx;"></image>
					<picker mode="date" :value="endTime" :start="startDeta" :end="endTime" @change="endDateChange">
						<view class="picker">
							{{endDetaL}}
						</view>
					</picker>
				</view>
				<button class="queryBut" @click="search">查询</button>
			</view>
			<view class="list-item" v-for="(item,index) in records" @click="todetails(item)">
				<view class="list-deta">{{item.days}}</view>
				<view class="list-center">
					<view class="center-left">
						<view class="center-title">交易金额</view>
						<view class="center-title">{{item.trxAmt}}元</view>
					</view>
					<view class="center-left">
						<view class="center-title">收益</view>
						<view class="center-title">{{item.syAmt}}元</view>
					</view>
				</view>
				<view class="list-bottom">
					<view class="bottom-left">
						<view class="bottom-item">
							<view class="bottom-title">新增会员</view>
							<view class="bottom-number">{{item.addUser}}</view>
						</view>
						<view class="bottom-item">
							<view class="bottom-title">激活数</view>
							<view class="bottom-number">{{item.jihuoNum}}</view>
						</view>
						<view class="bottom-item">
							<view class="bottom-title">达标奖励</view>
							<view class="bottom-number">{{item.dabiaoAmt}}</view>
						</view>
						<view class="border"></view>
					</view>
					<view class="bottom-left">
						<view class="bottom-item">
							<view class="bottom-title">分润奖励</view>
							<view class="bottom-number">{{item.fenrunAmt}}</view>
						</view>
						<view class="bottom-item">
							<view class="bottom-title">激活奖励</view>
							<view class="bottom-number">{{item.activationAmt}}</view>
						</view>
						<view class="bottom-item">
							<view class="bottom-title">推荐奖励</view>
							<view class="bottom-number">{{item.recommendAmt}}</view>
						</view>
					</view>
				</view>
			</view>

		<!-- </view> -->
	</mescroll-uni>
</template>

<script>
	import number from "../../utils/number.js";
	const api = require('../../config/api');
	const util = require('../../utils/util');
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mixins/mescroll-more-item.js";


	export default {
		mixins: [MescrollMixin, MescrollMoreItemMixin], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
		data() {
			return {
				number: number, //声明number属性并赋值为引入的number模块
				agentId: '',
				testphon: '',
				auditStatus: '',
				downOption: {
					auto: true // false不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption: {
					auto: false, // 不自动加载
					textLoading: '加载中 ...', // 加载中的提示文本
					textNoMore: '暂无更多', // 没有更多数据的提示文本
					// page: {
					// 	num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
					// 	size: 10 // 每页数据的数量
					// },
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty: {
						// use: false,
						icon: "",
						tip: '~ 暂无数据 ~', // 提示
						btnText: ''
					}
				},
				records: [], //列表数据
				startDeta: '开始时间',
				endDetaL: '结束时间',
				keyword: ''
			}
		},
		props: {
			i: Number, // 每个tab页的专属下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
			index: { // 当前tab的下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
				type: Number,
				default () {
					return 0
				}
			},
			tabs: { // 为了请求数据,演示用,可根据自己的项目判断是否要传
				type: Array,
				default () {
					return []
				}
			},
			height: [Number, String] // mescroll的高度
		},
		onShow() {
			// console.log(this.agentId);

			// this.testphon = uni.getStorageSync('phone')
			// this.downCallback();
			
			// console.log(this.testphon);
		},
		methods: {
			search(){
				this.downCallback();
			},
			startDateChange: function(e) {
				this.startDeta = e.detail.value
			},
			endDateChange: function(e) {
				this.endDetaL = e.detail.value
			},
			menuClick(index) {
				this.auditStatus = index
				this.downCallback();


			},

			// 代理商详情
			todetails(item) {
				uni.navigateTo({
					url: '/pages/indexChild/GoodsDetails/GoodsDetails?goodsId=' + item.id
				});
			},
			/*下拉刷新的回调 */
			downCallback() {
				// 这里加载你想下拉刷新的数据, 比如刷新轮播数据
				// loadSwiper();
				// 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
				this.mescroll.resetUpScroll()
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
			
				//联网加载数据
				// this.mescroll.endErr();
				this.keyword = this.tabs[this.i].dictValue
				if(this.keyword != 1){
					this.startDeta = '开始时间'
					this.endDetaL =  '结束时间'
				}
				let user = uni.getStorageSync('agentInfo')
				let keyword = this.tabs[this.i].dictValue
				let pageNum = page.num; // 页码, 默认从1开始
				let pageSize = page.size; // 页长, 默认每页10条
				const res = util.request(
					api.skUrl, {
						endTime: this.endDetaL=='结束时间'?'':this.endDetaL,
						limit: 10,
						page: 1,
						startTime: this.startDeta=='开始时间'?'':this.startDeta,
						type: keyword,
						userId: user.id,

					},
					'POST'
				).then(res => {
					console.log(res);
					//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
					let totalPage = res.data.pages;
					this.mescroll.endByPage(res.data.records.length, totalPage); //必传参数(当前页的数据个数, 总页数)
					// this.mescroll.endSuccess(res.data.records.length);
					//设置列表数据
					if (page.num == 1) this.records = []; //如果是第一页需手动制空列表
					this.records = this.records.concat(res.data.records); //追加新数据
				}).catch(() => {
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
			},
			//点击空布局按钮的回调
			emptyClick() {
				uni.showToast({
					title: '点击了按钮,具体逻辑自行实现'
				})
			}
		}
	}
</script>
<style lang="scss" scoped>
	// .Goos-List {
	// 	display: flex;
	// 	flex-wrap: wrap;
	// 	justify-content: space-between;
	// 	padding: 0 10px;
	// 	margin-bottom: 10px;
	// }

	// .Goos-List-item {
	// 	width: 48%;
	// 	background-color: #fff;
	// 	border-radius: 6px;
	// 	margin-top: 10px;
	// 	box-shadow: 1px 1px 3px 2px rgba(0, 0, 0, 0.04);

	// 	.item-img {
	// 		width: 100%;
	// 		height: 375rpx;
	// 		image{
	// 			width: 100%;
	// 			height: 100%;
	// 		}
	// 	}
	// }

	.goodsname {
		font-size: 28rpx;
		padding: 15rpx 30rpx 0 30rpx;
	}

	.goodsprice {
		padding: 0 30rpx 10rpx 30rpx;
	}

	.goodsprice>text:first-child {
		color: #E30F06;
		font-size: 22rpx;
	}

	.goodsprice>text:last-child {
		color: #E30F06;
		font-size: 28rpx;
	}

	.list-item {
		padding: 0 30rpx;
		border-bottom: 10rpx solid #eee;
	}

	.list-deta {
		font-size: 30rpx;
		padding: 25rpx 0;
	}

	.list-center {
		// background-color: #FF445B;
		background-color: #6A9FFB;
		display: flex;
		justify-content: space-around;
		align-items: center;
		padding: 20rpx 0;
		border-radius: 10rpx;
	}

	.center-left {
		text-align: center;
	}

	.center-title {
		font-size: 30rpx;
		color: #ffffff;
		padding: 5rpx 0;
	}

	.list-bottom {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-top: 25rpx;
	}

	.bottom-left {
		width: 46%;
		position: relative;
	}

	.border {
		position: absolute;
		right: -30rpx;
		top: 10rpx;
		width: 5rpx;
		height: 160rpx;
		background-color: #eee;
	}

	.bottom-item {
		display: flex;
		justify-content: space-between;
		align-content: center;
		padding-bottom: 15rpx;
	}

	.box {
	
		margin-bottom: 30rpx;
	}

	.van-tabs__wrap {
		border-bottom: 5px solid #eee;
	}

	.deliver-query {
		padding-top: 20rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		overflow: hidden;
		width: 690rpx;
		margin: 0rpx auto;
	}

	.deliver-time {
		color: #AEAEAE;
		font-size: 26rpx;
		width: 35%;
		height: 62rpx;
		line-height: 62rpx;
		text-align: center;
		background: white;
		/* border: 1px solid #AEAEAE; */
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 10rpx;
		border: 1rpx solid #f5f5ff;
	}

	.deliver-time>text {
		padding-left: 10rpx;
	}

	.line {
		color: #D2D2D2;
		font-size: 30rpx;
		padding: 0 20rpx;
	}

	.picker {
		padding-left: 15rpx;
	}

	.queryBut {
		width: 100rpx;
		height: 62rpx;
		background-color: #6A9FFB;
		font-size: 25rpx;
		padding: 0rpx;
		color: #fff;
		line-height: 62rpx;
		margin-left: 25rpx;
	}

	.queryBut::after {
		border: 0;

	}

	.bottom {
		display: flex;
		justify-content: center;
		padding: 40rpx 0;
	}

	.van-divider {
		border: none !important;
	}
</style>